<?php
/**
 * konwertuje string for frendlu url
 *
 * @param string $link // adres url
 * @param string $podmien // znaki na które zastąpią niechciane znaki
 * @param string $uwzglednij // pozostaw znaki
 * @return string
 * przykład
 * {$url|frendlyurl:-:[^0-9A-Za-z\-_\.]}
 */
function smarty_modifier_baner4page($page="",$path="",$default=""){
    if (empty($page)) {
    	if (empty($default))  return "baner4page: missing 'file' parameter";
        $page = $default;
    }

     $_image_path = $path.$page.".jpg";

     if(!file_exists($_image_path)) {
     	$_image_path = $path.$default.".jpg";
        if(!$_image_data = @getimagesize($_image_path)) {
            if(!file_exists($_image_path)) {
                return "/*baner4page: unable to find '$_image_path'*/";
            } else if(!is_readable($_image_path)) {
                return "/*baner4page: unable to read '$_image_path'*/";
            } else {
                return "/*baner4page: '$_image_path' is not a valid image file*/";
            }
        }     	
     }else{
        if(!$_image_data = @getimagesize($_image_path)) {
            if(!file_exists($_image_path)) {
                return "/*baner4page: unable to find '$_image_path'*/";
            } else if(!is_readable($_image_path)) {
                return "/*baner4page: unable to read '$_image_path'*/";
            } else {
                return "/*baner4page: '$_image_path' is not a valid image file*/";
            }
        }
     }
        if ($smarty->security &&
            ($_params = array('resource_type' => 'file', 'resource_name' => $_image_path)) &&
            (require_once(SMARTY_CORE_DIR . 'core.is_secure.php')) &&
            (!smarty_core_is_secure($_params, $smarty)) ) {
            return "/*baner4page: (secure) '$_image_path' not in secure directory*/";
        }        
        
        $width = $_image_data[0];
        $height = $_image_data[1];

	    return " background: url({$_image_path}) no-repeat;";
}
?>